﻿<%@ Page Title="" Language="C#" MasterPageFile="~/MaterPage/Site.Master" AutoEventWireup="true" CodeBehind="mapAPI.aspx.cs" Inherits="Js_Study.GoogleMap.mapAPI" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

    <asp:HiddenField ID="hid" runat="server" ClientIDMode="Static" />

    城市集合:<select id="sel">
    </select><br />

    城市:<input type="text" id="city" /><br />
    经度:<input type="text" id="weidu" />
    纬度:<input type="text" id="jingdu" />
    <br />
    Json:  
    <input type="text" id="result" style="width: 200px; border:1px dashed red" />
    <br />

    <input type="button" id="btn1" value="Get" />

    <asp:Button runat="server" Text="加载Excel" ID="load_excel" OnClick="load_excel_Click" />

    <input type="button" id="getcitys" value="GetCitys" />

    <input type="button" id="getArr" value="GetArr" />

    <script type="text/javascript">

        var geocoder;
        function init() {
            geocoder = new google.maps.Geocoder();
        }

        function codeAddress(city) {
            geocoder.geocode({ 'address': city.toString() }, function (result, status) {
                if (status == google.maps.GeocoderStatus.OK) {
                    var j = result[0].geometry.location.toString().split(',')[0].substring(1);
                    var w = result[0].geometry.location.toString().split(',')[1];

                    w = w.substring(1, w.length - 1);

                    j = parseFloat(j).toFixed(4);
                    w = parseFloat(w).toFixed(4)
                    $("#jingdu").val(j);
                    $("#weidu").val(w);
                    $("#city").val(city);
                    $("#result").val("[" + w + "," + j + "]");

                    //data format  city: [w, j],

                    arr.push(city + ":" + "[" + w + "," + j + "]");
                }
                else {
                    arr.push(city + ":error");
                    alert(status);
                }
            });
        }

        $("#btn1").click(function () {
            codeAddress($("#city").val());
        })

        $(function () {
            init();
        })

        var arr = [];

        $("#getcitys").click(function () {
            var vals = $("#hid").val().split(',');
            var sel = $("#sel");
            for (var i = 0; i < vals.length; i++) {
                var o = "<option>" + vals[i] + "</option>";
                sel.append($(o));
            }

            var count = 0;
            (function () {
                if (count == vals.length - 1) {
                    return;
                }

                codeAddress(vals[count]);
                console.log(vals[count] + "--" + arr.length);
                count++;
                var arg = arguments.callee;
                setTimeout(arg, 2000);
            })();
        })

        $("#getArr").click(function () {
            for (var i = 0; i < arr.length; i++) {

            }

            var val = arr.toString();
        })
    </script>
</asp:Content>
